package com.gzasc.eurekaserver.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import static org.springframework.security.config.Customizer.withDefaults;

@Configuration
public class WebSecurityConfig {

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
            .csrf(csrf -> csrf.disable())
            .authorizeHttpRequests(auth -> auth
                .requestMatchers("/eureka/**").authenticated() // 强制Eureka端点进行认证
                .anyRequest().authenticated() // 所有请求都需要认证
            )
            .httpBasic(withDefaults())
            .headers(headers -> headers
                .cacheControl(cache -> cache.disable()) // 禁用缓存
            );
        return http.build();
    }
}